<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>美丽说-用户注册</title>
	<link rel="stylesheet" href="/public/home/css/base.css" />
	<link rel="stylesheet" href="/public/home/css/global.css" />
	<link rel="stylesheet" href="/public/home/css/login-register.css" />
	<link rel="icon" href="/public/home/images/7d026282ff00a259b6a7b90eee6d_48_48.c5.png" type="image/x-icon"/>
	<meta name="csrf-token" content="{{ csrf_token() }}">

</head>
<body>
	<div class="header wrap1000">
		<a href=""><img src="/public/home/images/logo.png" alt="" /></a>
	</div>
	
	<div class="main">
		<div class="login-form-left fl">
			<dl class="func clearfix">
				<dt>注册之后您可以</dt>
				<dd class="ico05"><i></i>购买商品支付订单</dd>
				<dd class="ico01"><i></i>申请开店销售商品</dd>
				<dd class="ico03"><i></i>空间好友推送分享</dd>
				<dd class="ico02"><i></i>收藏商品关注店铺</dd>
				<dd class="ico06"><i></i>商品资讯服务评价</dd>
				<dd class="ico04"><i></i>安全交易诚信无忧</dd>
			</dl>
			
			<div class="if">
				<h2>如果您是本站用户</h2>
				<p>我已经注册过账号，立即 <a href="/login" class="register">登录</a> </p>
			</div>
		</div>
		
		<div class="login-form fr">
			<div style="color:red">
			@if(session("error"))
                {{session('error')}}
            @endif

            @if (count($errors) > 0)
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
            </div>
            @endif
			<div class="form-hd">
				<h3>用户注册</h3>
			</div>
			<div class="form-bd">
				<form action="{{url('/register')}}" method="POST">
					<dl>
						<dt>用户名</dt>
						<dd><input type="text" name="username" class="text" value="{{old('username')}}" /><span></span></dd>
					</dl>
					<dl>
						<dt>密码</dt>
						<dd><input type="password" name="password" class="text" value="{{old('password')}}" /></dd>
					</dl>
					<dl>
						<dt>确认密码</dt>
						<dd><input type="password" name="repassword" class="text" value="{{old('repassword')}}" /></dd>
					</dl>
					<dl>
						<dt>邮箱</dt>
						<dd><input type="text" name="email" class="text" value="{{old('email')}}" /><span></span></dd>
					</dl>
					<dl>
						<dt>手机号码</dt>
						<!-- <dd><input type="text" name="vcode" class="text" size="10" style="width:58px;"> <img src="/vcode" onclick="this.src=this.src+'?a=1'" align="absmiddle" style="position:relative;top:-2px;"/></dd> -->
						<dd><input type="text" name="phone" class="text" size="10" style="width:100px;"> <button type="button" id="message" style="width:118px;height:30px;" >获取验证码</button> </dd>
					</dl>
					<dl>
						<dt>验证码</dt>
						<!-- <dd><input type="text" name="vcode" class="text" size="10" style="width:58px;"> <img src="/vcode" onclick="this.src=this.src+'?a=1'" align="absmiddle" style="position:relative;top:-2px;"/></dd> -->
						<dd><input type="text" name="vcode" class="text" size="10" style="width:58px;"></dd>
					</dl>
					{{csrf_field()}}
					
					<dl>
						<dt>&nbsp;</dt>
						<dd><input type="submit" value="立即注册" class="submit"/> </dd>
					</dl>
				</form>
				
			</div>
			<div class="form-ft">
			</div>		
		</div>
	</div>
	
	<div class="footer clear wrap1000">
		<p> <a href="/">首页</a> | <a href="">招聘英才</a> | <a href="">广告合作</a> | <a href="">关于ShopCZ</a> | <a href="">联系我们</a></p>
		<p>Copyright 2004-2013 itcast Inc.,All rights reserved.</p>
	</div>
	<script type="text/javascript" src="/public/home/js/jquery.js"></script>
	<script type="text/javascript">
	$('#message').click(function(){
		//获取手机号码
		var v = $('input[name=phone]').val();
		//定义正则
		var reg = /^1\d{10}$/;
		//匹配
		var res = reg.test(v);
		//判断
		if(res){
			$('#message').attr('disabled','disabled');
			var i = 60;
			var init = setInterval(function(){
				$('#message').html(i+'秒后再次获取');
				i--;
				if(i == -1){
					$('#message').html('获取验证码');
					$('#message').removeAttr('disabled');
					clearInterval(init);
				}
			},1000);
			//发送ajax
			$.get('/send',{phone:v},function(data){
				if(data != '000000'){
					alert('请联系管理员.错误代码为:'+data);
				}
			},'json')
		}else{
			$('input[name=phone]').css('border','1px solid red');
		}
	})
	//全局变量 标识
	// alert($)
	var CUSER = false;
	var CEMAIL = false;


	//绑定表单提交事件
	$('form').submit(function(){
		//触发所有的丧失焦点事件
		$('input').trigger('blur');

		//判断所有的字段都检测成功后提交
		if(CUSER){
			//都成功
			return true;
		}

		//阻止默认行为
		return false;
	})

	//给所有的字段绑定获取焦点事件

	//给用户名绑定丧失焦点事件
	$('input[name=username]').blur(function(){
		//获取用户名
		var uname = $(this).val();
		//声明正则验证用户名是否合法
		var reg = /^\w{6,18}$/;
		var res = reg.test(uname);
		if(!res){
			//如果用户名不符合正则要求
			$(this).next().html('用户名格式不正确').css('color','red');
			//修改input边框颜色
			$(this).css('border','1px solid red');
			//修改全局变量
			CUSER = false;
			return false;
		}
		var inp = $(this);
		$.ajaxSetup({
		headers: {
		    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
		});
		//发送ajax
		$.ajax({
			url:"{{url('/register/ajax')}}",
			data:{name:uname},
			type:'get',
			// dataType:'json',
			success:function(data){
				//判断返回值
				if(data == 1){
					inp.next().html('ok').css('color','green');
					inp.css('border','1px solid green');
					//修改全局变量
					CUSER = true;
				}else{
					inp.next().html('用户名已存在,请更换').css('color','red');
					inp.css('border','1px solid red');
					//修改全局变量
					CUSER = false;
				}
			},
			error:function(){
				alert('ajax错误');
			},
			// timeout:2000,
			//同步
			async:false
		})
	})
	//给邮箱绑定丧失焦点事件
	$('input[name=email]').blur(function(){
		//获取用户输入的邮箱
		var email = $(this).val();
		//声明正则
		var reg = /^\w+@\w+\.(com|cn|com\.cn|org|net)$/;
		if(reg.test(email)){
			
			var inpe = $(this);
		//发送ajax
		$.ajax({
			url:"/register/ajaxa",
			data:{name:email},
			type:'get',
			// dataType:'json',
			success:function(data){
				// console.log(data);
				//判断返回值
				if(data == 1){
					inpe.next().html('ok').css('color','green');
					inpe.css('border','1px solid green');
					//修改全局变量
					CEMAIL = true;
				}else{
					inpe.next().html('邮箱已注册,请更换').css('color','red');
					inpe.css('border','1px solid red');
					//修改全局变量
					CEMAIL = false;
				}
			},
			error:function(){
				alert('ajax错误');
			},
			// timeout:2000,
			//同步
			async:false
		})
		}else{
			//错误
			$(this).next().html('邮箱格式不正确').css('color','red');
			$(this).css('border','1px solid red');
			CEMAIL = false;
		}

		
	})

	</script>
		
</body>
</html>
